import 'package:safetymonitor/app/components/custom_date_type.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_title_chart_page.dart';
import 'package:safetymonitor/app/components/custom_refresh.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/core/ext/ext.dart';
import 'package:safetymonitor/app/core/ext/widget_extension.dart';
import 'package:safetymonitor/app/data/entities/home/warning/alarm_resp_entity.dart';
import 'package:safetymonitor/generated/assets.dart';
import 'controller.dart';
///预警报警已完成
class AlarmCompletedPage extends StatelessWidget {
  AlarmCompletedPage({super.key});

  final controller = Get.put(CompletedController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Container(
            color: AppColors.bg_color_grey,
            padding: EdgeInsets.only(top: 12.w, right: 14.w, left: 14.w),
            child: CustomEasyRefreshList<AlarmRespEntity>(
              dataLoad: controller.getData,
              key: controller.globalKey,
              itemBuilder: (AlarmRespEntity item, int index) {
                return CustomTitleChartPage(
                  contentPadding: EdgeInsets.only(right: 16.w, left: 16.w, top: 16.w),
                  title: item.companyName,
                  titleRightWidget: controller.getStatueView(item.disposalStatus),
                  child: Stack(
                    children:  [
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Row(
                            children: [
                              Expanded(
                                child: _getTextView(
                                  title:
                                  '${CustomDateType.getDataType(item.dataType)}级别:',
                                  value: CustomDateType.getAlarmType(
                                      item.alarmLevel, item.dataType,
                                      isShow: true),
                                ),
                              ),
                              Expanded(
                                  child: _getTextView(
                                      title:
                                      '${CustomDateType.getDataType(item.dataType)}值:',
                                      value:'${item.val==0?'': item.val}')),
                            ],
                          ),
                          _getTextView(
                            title: '系统-类别:',
                            value: item.categoryZh,
                          ),
                          _getTextView(
                            title: '报警时长:',
                            value: '${item.alarmTimeMin}分钟'),
                          _getTextView(
                            title: '报警时间:',
                            value: '${item.alarmStartTime}'.millTS2Str()),
                        ],
                      ),
                      Visibility(
                        visible: item.status != 3,
                        child: Positioned(
                          right: 0,
                          bottom: 0,
                          child: SizedBox(
                            width: 56.w,
                            height: 36.w,
                            child: Stack(
                              alignment: Alignment.center,
                              children: [
                                SvgPicture.asset(
                                  Assets.svgIconEnter,
                                  fit: BoxFit.cover,
                                ),
                                Icon(
                                  Icons.arrow_forward,
                                  size: 20.w,
                                  color: Colors.white,
                                ).marginOnly(left: 7.w, top: 6.w)
                              ],
                            ),
                          ),
                        ),
                      )
                    ],
                  ).clickOnce(() {
                    controller.goDetails(item);
                  }),
                );
              },
            ),
          );
        });
  }

  /// 获取字段显示
  Widget _getTextView({required String title, required String value}) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              title,
              style: TextStyle(
                fontSize: 14.sp,
                height: 1.2,
                fontWeight: FontWeight.w400,
                color: const Color(0xffC7CEE5),
              ),
            ),
            AppGaps.hGap6,
            Expanded(
                child: Text(
                  value,
                  style: TextStyle(
                    fontSize: 14.sp,
                    height: 1.2,
                    fontWeight: FontWeight.w400,
                    color: const Color(0xff1D3452),
                  ),
                ))
          ],
        ),
        AppGaps.vGap10,
      ],
    );
  }
}
